package com.shanzmoo.platform.tomember.api.web.member;

import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.db.module.member.domain.vo.MemberAddressSaveDto;
import com.shanzmoo.db.module.member.domain.vo.MemberAddressUpdateDto;
import com.shanzmoo.db.module.member.domain.vo.MemberAddressVo;
import com.shanzmoo.db.module.merchant.domain.dto.MerchantInfoDto;
import com.shanzmoo.platform.tomember.api.manager.MemberAddressManager;
import com.shanzmoo.platform.tomember.api.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "会员")
@RestController
@RequestMapping("/member")
@RequiredArgsConstructor
public class MemberController {
    @Autowired
    private MemberAddressManager memberAddressManager;


    @ApiOperation(value = "新增会员地址")
    @PostMapping("/add/address")
    public SHttpResponse<Boolean> addAddress(@RequestBody MemberAddressSaveDto saveDto) {
        return memberAddressManager.addAddress(String.valueOf(SecurityUtil.getCurrentUserId()), saveDto);
    }

    @ApiOperation(value = "会员地址列表")
    @GetMapping("/address/list")
    public SHttpResponse<List<MemberAddressVo>> getAddressList() {
        return memberAddressManager.getAddressList(String.valueOf(SecurityUtil.getCurrentUserId()));
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete/address")
    public SHttpResponse<Boolean> deleteById(@ApiParam(value = "地址id") @RequestParam(value = "id") Integer id) {
        return  memberAddressManager.deleteById(id, String.valueOf(SecurityUtil.getCurrentUserId()));
    }

    @ApiOperation(value = "修改会员地址")
    @PostMapping("/update/address")
    public SHttpResponse<Boolean> updateAddress(@RequestBody MemberAddressUpdateDto updateDto) {
        return memberAddressManager.updateAddress(String.valueOf(SecurityUtil.getCurrentUserId()), updateDto);
    }



}
